package org.zad1;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class FunkcjeSbox {

	private List<String> functions = Collections.emptyList();
	private Sbox sbox;

	public FunkcjeSbox(Sbox sbox)
	{
		functions = new ArrayList<String>();
		this.sbox = sbox;
	}
	
	public void init(int funCount)
	{
		for(int i = funCount-1; i >= 0; i--)
		{
			String fun = "";
			for(int j=0; j< sbox.size(); j++)
			{
				fun += FunUtil.getBit(sbox.get(j), i);
			}
			functions.add(fun);
		}
	}
	
	public String get(int index)
	{
		return functions.get(index);
	}
	
	public void display()
	{
		for(String s: functions)
		{
			System.out.println(s);
		}
	}
	
	public void saveToFile(String path)
	{
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(path));
			for(String s : functions)
			{
				out.write(s + "\n");
			}
			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
